// @ts-check
import { formatTree } from '@/utils/common'
import { defineStore } from 'pinia'

export const useAirCityStore = defineStore({
	id: 'aircity',
	state: () =>
		({
			AirCityPlayer: null,
			AirCityApi: null,
			TreeInfo: null,
			IsOnReady: false,
			// 现在所在页面或模块
			nowLocal: '',
			layerTreeObject: {},
			animationList: [],
		} as any),
	getters: {
		GetformatByTree: (state) => formatTree(state.TreeInfo.filter((ele: any) => ele.iD !== 'ProjectTree_Root')), //树状结构图层树
		GetTreeIdByName: (state) => {
			//根据图层名称获取图层ID  传参：字符串/字符串数组
			return (n: string | string[]) => {
				const names = Array.isArray(n) ? n : [n]
				let filterTrees: any = []
				state.TreeInfo?.forEach((ele: any) => {
					let index = names.findIndex((name) => name == ele.name)
					index > -1 && (filterTrees[index] = ele)
				})

				return filterTrees.map((ele: any) => ele.iD)
			}
		},
	},
	actions: {
		async setLayerTreeObject(layerTreeObject: any) {
			this.layerTreeObject = layerTreeObject
		},
		async setAirCityPlayer(param: any) {
			this.AirCityPlayer = param
		},
		async setAirCityApi(param: any) {
			this.AirCityApi = param
		},
		async setTreeInfo(param: any) {
			this.TreeInfo = param
		},
		async setIsOnReady(param: any) {
			this.IsOnReady = param
		},
		async setnowLocal(param: any) {
			this.nowLocal = param
		},
		async setAnimationList(param: any) {
			this.animationList = param
		},
	},
})
